#ifndef STDTYPES_H
#define STDTYPES_H

#include "sys.h"
#include <time.h>

typedef unsigned char u8;
typedef unsigned short int u16;
typedef unsigned int u32;
typedef unsigned long long u64;

#define SUCCESS 0
#define FAILURE 1

// #define CURRENT_LOG_LEVEL LOG_LEVEL_WARNNING
#define EN_LOG_PRINT

typedef enum {
    LOG_LEVEL_DEBUG,
    LOG_LEVEL_INFO,
    LOG_LEVEL_WARNNING,
    LOG_LEVEL_ERROR,
    LOG_LEVEL_FATAL
} LOG_LEVEL;

volatile LOG_LEVEL dbg_switch;
#ifdef EN_LOG_PRINT

#define F_RED 31
#define F_GREEN 32
#define F_YELLOW 33
#define F_CYAN 36
#define F_BLUE 34
#define F_PURPLE 35

#define C_DEFAULT 0
#define C_HIGHTLIGHT 1
#define C_UNDERLINE 4

#define LOG_MSG(lev, color, ctr, fmt, ...)                              \
if (dbg_switch <= lev)                                                  \
{                                                                       \
    time_t _time;                                                       \
    time(&_time);                                                       \
    struct tm* now = localtime(&_time);                                 \
    mnet_printf("\033[%d;%dm""[%d:%d:%d][%s:%d]"fmt"\033[0m",           \
                 ctr, color, now->tm_hour, now->tm_min,                 \
                 now->tm_sec, __FUNCTION__, __LINE__, ##__VA_ARGS__);   \
}

#define LOG_DEBUG(fmt, ...) LOG_MSG(LOG_LEVEL_DEBUG, F_CYAN, C_DEFAULT, fmt, ##__VA_ARGS__)

#define LOG_INFO(fmt, ...) LOG_MSG(LOG_LEVEL_INFO, F_GREEN, C_DEFAULT, fmt, ##__VA_ARGS__)

#define LOG_WARNNING(fmt, ...) LOG_MSG(LOG_LEVEL_WARNNING, F_YELLOW, C_UNDERLINE, fmt, ##__VA_ARGS__)

#define LOG_ERROR(fmt, ...) LOG_MSG(LOG_LEVEL_ERROR, F_PURPLE, C_UNDERLINE, fmt, ##__VA_ARGS__)

#define LOG_FATAL(fmt, ...) LOG_MSG(LOG_LEVEL_FATAL, F_RED, C_HIGHTLIGHT, fmt, ##__VA_ARGS__)
#else
#define LOG_FATAL(...)
#define LOG_ERROR(...)
#define LOG_WARNNING(...)
#define LOG_INFO(...)
#define LOG_DEBUG(...)
#endif

#endif